package com.hzqy.persistence.dao.pms;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.hzqy.web.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.hzqy.persistence.dao.core.PersistenceDao;


@Repository
public class PmsDao extends PersistenceDao<PmsUserVo, Integer>{
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	public int findUserIsExist(PmsUserVo puv) {
		return findQuantity("findUserIsExist", puv);
	}
	
	public int findRoleIsExist(PmsRoleVo prv) {
		return findQuantity("findRoleIsExist", prv);
	}
	
	public PmsUserVo findUser(PmsUserVo puv) {
		return findOne("findUser", puv);
	}

	public PmsUserVo findUserByName(PmsUserVo puv) {
		String namespace = this.getNamespace();
		return getSqlSession().selectOne(namespace + "findUserByName", puv);
	}

	public List<PmsResourceVo> findUserResourcesByRoleId(PmsUserVo puv) {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "findUserResourcesByRoleId",puv);
	}
	
	public int findUserCount(PmsUserVo puv) {
		return this.findQuantity("findUserCount", puv);
	}
	
	public int findAdminUserCount(PmsUserVo puv) {
		return this.findQuantity("findAdminUserCount", puv);
	}
	
	public List<PmsUserVo> findUserList(Map<String,Object> map){
		return this.findList("findUserList", map);
	}
	
	public List<PmsUserVo> findAdminUserList(Map<String,Object> map){
		return this.findList("findAdminUserList", map);
	}
	
	public int delUserStatus(int f_pu_id) {
		return update("delUserStatus", f_pu_id);
	}
	
	public int delUser(int f_pu_id) {
		String namespace = this.getNamespace();
		return getSqlSession().delete(namespace + "deleteUserFromOrgUser", f_pu_id);
	}
	
	public int delRoleStatus(int f_prole_id) {
		return update("delRoleStatus",f_prole_id);
	}
	
	public int delRole(int f_prole_id) {
		String namespace = this.getNamespace();
		return getSqlSession().delete(namespace + "deleteRoleFromOrgRole", f_prole_id);
	}
	
	public int delAttributeStatus(int f_pa_id) {
		return update("delAttributeStatus",f_pa_id);
	}
	
	public int delRoleResourceAttByAttId(int f_prra_attributeId) {
		String namespace = this.getNamespace();
		return getSqlSession().delete(namespace + "delRoleResourceAttByAttId", f_prra_attributeId);
	}
	
	public int delResourceStatus(int f_pr_id) {
		return update("delResourceStatus", f_pr_id);
	}
	
	public PmsUserVo findUserById(int f_pu_id) {
		return findById("findUserById", f_pu_id);
	}
	
	public PmsRoleVo findRoleById(int f_prole_id) {
		String namespace = this.getNamespace();
		return getSqlSession().selectOne(namespace + "findRoleById", f_prole_id);
	}
	
	public PmsAttributeVo findAttributeById(int f_pa_id) {
		String namespace = this.getNamespace();
		return getSqlSession().selectOne(namespace + "findAttributeById", f_pa_id);
	}
	
	public int insertUser(PmsUserVo puv) {
		return insert("insertUser", puv);
	}
	public int insertUserHistory(PmsUserVo puv) {
		return insert("insertUserHistory", puv);
	}

	public int insertRole(PmsRoleVo prv) {
		String namespace = this.getNamespace();
		return getSqlSession().insert(namespace + "insertRole", prv);
	}
	
	public int insertAttribute(PmsAttributeVo pav) {
		String namespace = this.getNamespace();
		return getSqlSession().insert(namespace + "insertAttribute", pav);
	}
	
	public List<PmsResourceVo> selectResourceList(PmsResourceVo prv){
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectResource",prv);
	}
	
	public List<PmsOrgVo> selectOrgList() {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectOrgList");
	}

	public List<PmsOrgVo> selectOrgListByGgmodel() {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectOrgListByGgmodel");
	}
	
	public int findOrgVoCount(PmsOrgVo pmsOrgVo) {
		String namespace = this.getNamespace();
		return getSqlSession().selectOne(namespace + "findOrgVoCount", pmsOrgVo);
	}
	
	public List<PmsOrgVo> findOrgVoList(Map<String,Object> map){
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "findOrgVoList", map);
	}
	
	public List<PmsOrgVo> selectOrgByOrgId(PmsUserVo userVo) {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectOrgByOrgId",userVo);
	}
	
	public PmsResourceVo selectResource(int f_pr_id) {
		String namespace = this.getNamespace();
		return getSqlSession().selectOne(namespace + "selectResourceById", f_pr_id);
	}
	
	public int addResource(PmsResourceVo resourceVo) {
		String namespace = this.getNamespace();
		return getSqlSession().insert(namespace + "insertResource", resourceVo);
	}
	
	public int updateResourve(PmsResourceVo resourveVo) {
		String namespace = this.getNamespace();
		return getSqlSession().update(namespace + "updateResource", resourveVo);
	}
	
	public int updateRole(PmsRoleVo prv) {
		String namespace = this.getNamespace();
		return getSqlSession().update(namespace + "updateRole", prv);
	}
	
	public int updateAttribute(PmsAttributeVo pav) {
		String namespace = this.getNamespace();
		return getSqlSession().update(namespace + "updateAttribute", pav);
	}
	
	public int findRoleCount(Map map) {
		String namespace = this.getNamespace();
		return getSqlSession().selectOne(namespace + "findRoleCount", map);
	}
	
	public int findAdminRoleCount(PmsRoleVo prv) {
		String namespace = this.getNamespace();
		return getSqlSession().selectOne(namespace + "findAdminRoleCount", prv);
	}
	
	public int findAttributeCount(int f_pa_resourceId) {
		String namespace = this.getNamespace();
		return getSqlSession().selectOne(namespace + "findAttributeCount", f_pa_resourceId);
	}
	
	public List<PmsRoleVo> findRoleList(Map<String,Object> map){
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "findRoleList", map);
	}
	
	public List<PmsRoleVo> findAdminRoleList(Map<String,Object> map){
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "findAdminRoleList", map);
	}
	
	public List<PmsAttributeVo> findAttributeList(Map<String,Object> map) {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "findAttributeList", map);
	}
	
	public List<PmsAttributeVo> selectAttributeList() {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectAttributeList");
	}
	
	public int deleteRoleResAtt(int f_prra_roleId) {
		String namespace = this.getNamespace();
		return getSqlSession().delete(namespace + "deleteRoleResAtt", f_prra_roleId);
	}
	
	public int insertRoleResAtt(PmsRoleResourceAttributeVo prra) {
		String namespace = this.getNamespace();
		return getSqlSession().insert(namespace + "insertRoleResAtt", prra);
	}
	
	public List<PmsRoleResourceAttributeVo> selectRoleAttribute(int f_prra_roleId) {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectRoleAttribute", f_prra_roleId);
	}
	
	public List<PmsUserVo> selectOrgUserList() {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectOrgUser");
	}
	
	public List<PmsRoleVo> selectOrgRoleList() {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectOrgRoleList");
	}
	
	public List<PmsRoleVo> selectOrgRoleList(int orgId) {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectOrgRoleListNotAdmin",orgId);
	}
	
	public int insertOrg(PmsOrgVo pov) {
		String namespace = this.getNamespace();
		return getSqlSession().insert(namespace + "insertOrg", pov);
	}
	
	public int insertOrgUser(PmsOrgUserVo pouv) {
		String namespace = this.getNamespace();
		return getSqlSession().insert(namespace + "insertOrgUser", pouv);
	}
	
	public int insertOrgRole(PmsOrgRoleVo porv) {
		String namespace = this.getNamespace();
		return getSqlSession().insert(namespace + "insertOrgRole", porv);
	}
	
	public PmsOrgVo selectOrg(int f_po_id) {
		String namespace = this.getNamespace();
		return getSqlSession().selectOne(namespace + "selectOrg", f_po_id);
	}
	
	public List<PmsUserVo> selectUserOrg(int f_po_id) {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectUserOrg",f_po_id);
	}
	
	public List<PmsRoleVo> selectRoleByOrgId(int f_po_id) {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectRoleByOrgId",f_po_id);
	}
	
	public List<PmsOrgRoleVo> selectOrgRole(int f_po_id) {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectOrgRole",f_po_id);
	}
	
	public int updateOrg(PmsOrgVo pov) {
		String namespace = this.getNamespace();
		return getSqlSession().update(namespace + "updateOrg", pov);
	}
	
	public int deleteOrgUser(PmsOrgVo pov) {
		String namespace = this.getNamespace();
		return getSqlSession().delete(namespace + "deleteOrgUser", pov);
	}
	
	public int deleteOrgRole(PmsOrgVo pov) {
		String namespace = this.getNamespace();
		return getSqlSession().delete(namespace + "deleteOrgRole", pov);
	}
	
	public List<PmsOrgUserRoleVo> selectOrgUserRole(int f_po_id) {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectOrgUserRole", f_po_id);
	}
	
	public int deleteOrgUserRole(int f_po_id) {
		String namespace = this.getNamespace();
		return getSqlSession().delete(namespace + "deleteOrgUserRole", f_po_id);
	}
	
	public int insertOrgUserRole(PmsOrgUserRoleVo pourv) {
		String namespace = this.getNamespace();
		return getSqlSession().insert(namespace + "insertOrgUserRole", pourv);
	}
	
	public int deleteOrg(int f_po_id) {
		String namespace = this.getNamespace();
		return getSqlSession().update(namespace + "deleteOrg", f_po_id);
	}
	
	public List<PmsAttributeVo> selectUserAttributeList(PmsUserVo puv) {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectUserAttributeList",puv); 
	}
	
	public List<PmsResourceVo> selectUserResourceList(PmsUserVo puv) {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectUserResourceList",puv); 
	}
	
	public PmsUserVo selectPwdById(PmsUserVo puv) {
		String namespace = this.getNamespace();
		return getSqlSession().selectOne(namespace + "selectPwdById",puv); 
	}
	
	public int updatePassword(PmsUserVo puv) {
		String namespace = this.getNamespace();
		return getSqlSession().update(namespace + "updatePassword", puv);
	}
	
	public List<PmsResourceVo> selectAllResource() {
		return getSqlSession().selectList(this.getNamespace() + "selectAllResource");
	}
	
	public List<PmsAttributeVo> selectAllAttribute() {
		return getSqlSession().selectList(this.getNamespace() + "selectAllAttribute");
	}
	
	public int findOrgCount(PmsOrgVo pmsOrgVo) {
		String namespace = this.getNamespace();
		return getSqlSession().selectOne(namespace + "findOrgCount", pmsOrgVo);
	}
	
	public List<PmsOrgVo> selectOrgListByParentId(Map<String, Object> map) {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectOrgListByParentId", map);
	}

	public List<PmsOrgVo> selectAuthorityOrgListByParentId(int parentId) {
		return getSqlSession().selectList(this.getNamespace() + "selectAuthorityOrgListByParentId", parentId);
	}
	
	public int updateOrgStatus(int f_po_id,int f_po_status) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("f_po_id", f_po_id);
		map.put("f_po_status", f_po_status);
		String namespace = this.getNamespace();
		return getSqlSession().update(namespace + "updateOrgStatus", map);
	}

	public int openVistualChannel(PmsOrgVo pmsOrgVo) {
		return getSqlSession().update(this.getNamespace() + "openVistualChannel", pmsOrgVo);
	}

	public int updateVistualStatus(PmsOrgVo pmsOrgVo) {
		return getSqlSession().update(this.getNamespace() + "updateVistualStatus", pmsOrgVo);
	}
	
	public List<CmLabelOrgVo> selectLabelBind(int f_clo_orgid) {
		return getSqlSession().selectList(this.getNamespace() + "selectLabelBind",f_clo_orgid);
	}
	
	public int deleteLabelBind(CmLabelOrgVo cmLabelOrgVo) {
		return getSqlSession().delete(this.getNamespace() + "deleteLabelBind",cmLabelOrgVo);
	}
	
	public int insertLabelBind(CmLabelOrgVo cmLabelOrgVo) {
		return getSqlSession().insert(this.getNamespace() + "insertLabelBind",cmLabelOrgVo);
	}
	
	public List<PmsOrgVo> selectOrgByOrgName(String f_po_name,int f_po_id){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("f_po_id", f_po_id);
		map.put("f_po_name", f_po_name);
		return getSqlSession().selectList(this.getNamespace() + "selectOrgByOrgName",map);
	}
	
	public List<SysProductVo> selectProductList() {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectProductList");
	}

	public List<String> selectWords() {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "selectWords");
	}

	public List<PmsUserVo> findUserOperatedList(PmsUserVo userVo) {
		String namespace = this.getNamespace();
		return getSqlSession().selectList(namespace + "findUserOperatedList",userVo);
	}
	public int findUserHistoryPWdCount(PmsUserVo userVo) {
		String namespace = this.getNamespace();
		return getSqlSession().selectOne(namespace + "findUserHistoryPWdCount",userVo);
	}
	public PmsUserVo findLastUserHistoryPwd(PmsUserVo userVo) {
		String namespace = this.getNamespace();
		return getSqlSession().selectOne(namespace + "findLastUserHistoryPwd",userVo);
	}

	public int  updateUserStatus(PmsUserVo userVo){
		 String namespace = this.getNamespace();
		 return getSqlSession().update(namespace + "updateUserStatus",userVo);
	}

}
